package com.lagou.mapper;

import com.lagou.pojo.Order;
import com.lagou.pojo.User;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@CacheNamespaceRef(OrdersMapper.class) // 开启二级缓存
public interface OrdersMapper extends Mapper<Order> {

    @Select("select * from orders")
    List<Order> findAll();

    List<Order> findAllInfo();

    @Select("select * from orders where id=#{id}")
    Order findById(int id);

    @Select("select * from orders where uid=#{id}")
    Order findByUid(int id);

    // 一对一
    @Select("select * from orders")
    @Results({
            @Result(id=true,property = "id",column = "id"),
            @Result(property = "ordertime",column = "ordertime"),
            @Result(property = "total",column = "total"),
            @Result(property = "user",column = "uid",
                    javaType = User.class,
                    one = @One(select = "com.lagou.mapper.UserMapper.findById"))
    })
    List<Order> findAllOrdersAndUserAnnotation();

}
